package org.com.myfb.action;

import java.util.List;

import org.com.myfb.dao.PersonDaoInter;
import org.com.myfb.model.Person;
import org.com.myfb.model.Teachers;
import org.com.myfb.service.PersonServiceInter;

import com.opensymphony.xwork2.ActionSupport;

public class AddTeacherAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PersonDaoInter personDaoImpl;
	private PersonServiceInter personServiceImpl;
	private String num;
	private String psw;
	private int tid;
	private String tname;
	private Teachers teachers;
	private String data;
	
	

	
	public PersonDaoInter getPersonDaoImpl() {
		return personDaoImpl;
	}



	public void setPersonDaoImpl(PersonDaoInter personDaoImpl) {
		this.personDaoImpl = personDaoImpl;
	}

	

	public PersonServiceInter getPersonServiceImpl() {
		return personServiceImpl;
	}



	public void setPersonServiceImpl(PersonServiceInter personServiceImpl) {
		this.personServiceImpl = personServiceImpl;
	}



	public String getNum() {
		return num;
	}



	public void setNum(String num) {
		this.num = num;
	}



	public String getPsw() {
		return psw;
	}



	public void setPsw(String psw) {
		this.psw = psw;
	}



	public int getTid() {
		return tid;
	}



	public void setTid(int tid) {
		this.tid = tid;
	}



	public String getTname() {
		return tname;
	}



	public void setTname(String tname) {
		this.tname = tname;
	}



	public String getData() {
		return data;
	}



	public void setData(String data) {
		this.data = data;
	}



	public String execute(){
		Person person = new Person();
		Teachers teacher = new Teachers();
		String where = " num = " + "'" + this.getNum() + "'";
		List<Person> persons = this.getPersonDaoImpl().findList(Person.class, where);
		if(persons.size()>0){
			this.setData("[{\"message\":\"2\"}]");
			return ERROR;
		}else{
			this.getPersonServiceImpl().addTeacher(person,teacher,this.getNum(),this.getPsw(),this.getTid(),this.getTname());
			this.setData("[{\"message\":\"1\"}]");
			return SUCCESS;
		}
	}
}
